package com.meizi.mall.product.config;

import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author meizi
 * @email enjoymeizi@gmail.com
 * @date 2021/1/27 15:35
 */
@EnableConfigurationProperties(ExecutorPoolConfig.class)
@Component
public class MyExecutor {
    @Bean
    ThreadPoolExecutor executor(ExecutorPoolConfig executorPoolConfig){
       return new ThreadPoolExecutor(executorPoolConfig.getCorePoolSize(),
                executorPoolConfig.getMaximumPoolSize(),
                executorPoolConfig.getKeepAliveTime(),
                TimeUnit.MILLISECONDS,
                new LinkedBlockingQueue<Runnable>(),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy());

    }
}
